/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
  * Name: inner_utils.h
  *
  * Purpose: inner helper for implementation 'COM' Functional
  *
  * Developer:
  *   wen.gu , 2020-06-12
  *
  * TODO:
  *
  ***************************************************************************/

  /******************************************************************************
   **    INCLUDES
   ******************************************************************************/
#ifndef __PANDA_COM_INTERNAL_INNER_UTILS_H__
#define __PANDA_COM_INTERNAL_INNER_UTILS_H__

#include "panda/com/com_types.h"

/******************************************************************************
 **    MACROS
 ******************************************************************************/

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace panda
{
namespace com 
{
namespace internal_impl
{
/**todo something */
/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/
/**for check the base type of enum */
template<size_t sz = 1>
struct enum2Int 
{
    using type = uint8_t;
};

template<>
struct enum2Int<2>
{
    using type = uint16_t;
};

template<>
struct enum2Int<4>
{
    using type = uint32_t;
};

template<>
struct enum2Int<8>
{
    using type = uint64_t;
};

/** for check target has member function: void Serialize(Serializer& ser); */
template<typename T, typename... Args>
struct has_member_serialize
{
private:
    template<typename U> static auto Check(int) -> decltype(std::declval<U>().Serialize(std::declval<Args>()...), std::true_type());
    template<typename U> static std::false_type Check(...);
public:
    //static constexpr auto value = decltype(Check<T>(0))::value;
    enum { value = std::is_same<decltype(Check<T>(0)), std::true_type>::value };
};

/** for check target has member function: void Deserialize(Deserializer& dsr); */
template<typename T, typename... Args>
struct has_member_deserialize
{
private:
    template<typename U> static auto Check(int) -> decltype(std::declval<U>().Deserialize(std::declval<Args>()...), std::true_type());
    template<typename U> static std::false_type Check(...);
public:
    //static constexpr auto value = decltype(Check<T>(0))::value;
    enum { value = std::is_same<decltype(Check<T>(0)), std::true_type>::value };
};

} /** namespace internal_impl */
} /** namespace com */
} /** namespace panda */


#endif /** !__PANDA_COM_INTERNAL_INNER_UTILS_H__ */